package lan;

public class 魔方 {
    public static void main(String[] args){
     int[][] arr=new int[10][10];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j <arr.length; j++) {
                arr[i][j]=j+i*10;
            }
        }
        for (int i = 0; i < 100; i++) {
            reverseRow(arr, (int) (Math.random()*10));
            reverseColumn(arr, (int) (Math.random()*10));
            changeColumn(arr,(int) (Math.random()*10),(int) (Math.random()*10));
            changeRow(arr,(int) (Math.random()*10),(int) (Math.random()*10));
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println();
            for (int j = 0; j < arr.length; j++) {
                System.out.print(arr[i][j]+" ");
            }
        }
    }
    public static void changeColumn(int array[][],int col1,int col2) {
        for (int i = 0; i < array.length; i++) {
           int temp=array[i][col1];
           array[i][col1]=array[i][col2];
            array[i][col2]=temp;
        }
    }
    public static void changeRow(int array[][],int row1,int row2) {
        for (int i = 0; i < array.length; i++) {
            int temp=array[row1][i];
            array[row1][i]=array[row2][i];
            array[row2][i]=temp;
        }
    }
    public static void reverseColumn(int array[][],int col) {
        int rows = array.length;
        for (int i = 0; i < rows / 2; i++) {
            int temp = array[i][col];
            array[i][col] = array[rows - 1 - i][col];
            array[rows - 1 - i][col] = temp;
        }
    }
    public static void reverseRow(int[][] array, int row) {
        int cols = array[row].length;
        for (int i = 0; i < cols / 2; i++) {
            int temp = array[row][i];
            array[row][i] = array[row][cols - 1 - i];
            array[row][cols - 1 - i] = temp;
        }
    }

}



